/**
 * Created by spatra on 14-9-7.
 */

define(['QUnit', 'app/entity'], function(QUnit, Entity) {

	var initStatus = {
		radius: 10,
		x: 22,
		y: 10,
		vx: 5,
		vy: 7,
		ax: 0,
		ay: 2
	};

	var run = function() {

		function buildEntity(){
			return new Entity(initStatus.radius,
				initStatus.x, initStatus.y,
				initStatus.vx, initStatus.vy,
				initStatus.ax, initStatus.ay);
		}

		QUnit.module('Entity');

		QUnit.test('测试Entity的构造函数(不填写任何初始化参数)', function (assert) {

			var theEntity = new Entity();

			assert.equal(theEntity.radius, 1, '半径');
			assert.equal(theEntity.x, 0, '位置x');
			assert.equal(theEntity.y, 0, '位置y');
			assert.equal(theEntity.vx, 0, '速度vx');
			assert.equal(theEntity.vy, 0, '速度vy');
			assert.equal(theEntity.ax, 0, '加速度ax');
			assert.equal(theEntity.ay, 0, '加速度ay');

			assert.equal(theEntity.collision, false, '碰撞状态');
			assert.equal(theEntity.dragStatus, false, '拖拉状态');

		});

		QUnit.test('测试Entity的构造函数（附带初始化参数)', function (assert) {
			var theEntity = buildEntity();

			assert.equal(theEntity.radius, initStatus.radius, '半径');
			assert.equal(theEntity.x, initStatus.x, '位置x');
			assert.equal(theEntity.y, initStatus.y, '位置y');
			assert.equal(theEntity.vx, initStatus.vx, '速度vx');
			assert.equal(theEntity.vy, initStatus.vy, '速度vy');
			assert.equal(theEntity.ax, initStatus.ax, '加速度ax');
			assert.equal(theEntity.ay, initStatus.ay, '加速度ay');
		});

		QUnit.test('测试Entity的随机状态设置函数', function(assert){
			var theEntity = buildEntity();

			var maxVel = 20;
			theEntity.setRandomVelocity(maxVel);
			assert.ok( Math.abs(theEntity.vx) <= maxVel && Math.abs(theEntity.vy) <= maxVel, '设置随机速度（传递最大速度的数值参数）');

			maxVel = {maxVx: 2, maxVy: 7};
			theEntity.setRandomVelocity(maxVel);
			assert.ok( Math.abs(theEntity.vx) <= maxVel.maxVx && Math.abs(theEntity.vy) <= maxVel.maxVy, '设置随机速度（传递最大速度的对象)');

			var maxRadius = 20;
			theEntity.setRandomRadius(maxRadius);
			assert.ok( theEntity.radius <= maxRadius, '设置随机半径');

			var containerWidth = 30, containerHeight = 50;
			theEntity.setRandomPosition(containerWidth, containerHeight);
			assert.ok( theEntity.x <= containerWidth && theEntity.y <= containerHeight, '设置随机位置');

			maxVel = 45;
			maxRadius = 15;
			containerHeight = 100;
			containerWidth = 200;
			theEntity.setRandomStatus(maxVel, maxRadius, containerWidth, containerHeight);
			assert.ok( Math.abs(theEntity.vx) <= maxVel && Math.abs(theEntity.vy) <= maxVel, '设置随机速度（传递最大速度的数值参数）');
			assert.ok( theEntity.radius <= maxRadius, '设置随机半径');
			assert.ok( theEntity.x <= containerWidth && theEntity.y <= containerHeight, '设置随机位置');

		});

		QUnit.test('测试Entity的对外函数', function(assert){
			var entityA = new Entity(5, 2, 2), //6 8 10
				entityB = new Entity(5, 8, 9);

			assert.ok( Entity.checkCollision(entityA, entityB), '(checkCollision)碰撞');


			entityB.y = 11;
			assert.ok( !Entity.checkCollision(entityA, entityB), '(checkCollision)非碰撞');
		});
	};

return {
	run: run,
	setInitStatus: function(setting){
		initStatus = setting;
	}
};

});
